import { Body, Controller, Get, Post, HttpStatus, HttpCode, Delete, ParseIntPipe, Param, UseGuards, Put } from '@nestjs/common';
import { ApiOperation, ApiCreatedResponse, ApiTags } from '@nestjs/swagger';
import { AuthGuard } from '@nestjs/passport';
import { UserService } from '../../../service/user/user.service'
import { CreateUserDto } from './dto/createUser.dto'
import { UserListDto } from './dto/user.list.dto';
import { UserListVo } from './vo/user.vo';
import { CurrentUser, ICurrentUserType } from 'src/decorators/current_user';
@ApiTags('后台管理-用户新增')//用于生成标题分类
@UseGuards(AuthGuard('jwt'))
@Controller()
export class UserController {
    constructor(private userService: UserService) { }
    @ApiOperation({
        summary: '用户新增',
        description: '用户新增',
    })
    @ApiCreatedResponse({
        status: 200,
        description: '成功时返回的数据',
    })
    @Post('add')
    @HttpCode(HttpStatus.OK)
    async userAdd(@Body() createUserDto: CreateUserDto) {
        const message = await this.userService.add(createUserDto)
        return message
    }

    @ApiOperation({ summary: '删除账号', description: '根据id删除账号' })
    @ApiCreatedResponse({
        type: String,
        description: '修改账号返回值',
    })
    @HttpCode(HttpStatus.OK)
    @Delete('remove/:id')
    async destroyById(@Param('id', new ParseIntPipe()) id: number): Promise<string> {
        return await this.userService.remove(id);
    }

    @ApiOperation({
        summary: '用户修改',
        description: '用户修改',
    })
    @ApiCreatedResponse({
        status: 200,
        description: '成功时返回的数据',
    })
    @HttpCode(HttpStatus.OK)
    @Put('update/:id')
    async userUpdate(@Param('id', new ParseIntPipe()) id: number, @Body() body: CreateUserDto) {
        const result = await this.userService.update(id, body)
        return result
    }

    @ApiOperation({
        summary: '用户查找',
        description: '用户查找',
    })
    @ApiCreatedResponse({
        status: 200,
        description: '成功时返回的数据',
    })
    @Get('find/:id')
    @HttpCode(HttpStatus.OK)
    async userFind(@Param('id', new ParseIntPipe()) id: number) {
        return await this.userService.findById(id)
    }
    
    @ApiOperation({
        summary: '用户查找',
        description: '用户查找',
    })
    @ApiCreatedResponse({
        status: 200,
        description: '成功时返回的数据',
    })
    @Post('findAll')
    @HttpCode(HttpStatus.OK)
    async userFindSelect(@CurrentUser() userInfo: ICurrentUserType,@Body() body: UserListDto): Promise<UserListVo>{
        return await this.userService.findAll(body)
    }
}
